/**
 * 流程管理JavaScript
 */

 var path = "/ywpt";
//申请业务表单联动查询时使用
function onChanged(data) {
	var nextTask = mini.getbyName("nextTaskId");
	var nextUser = mini.getbyName("nextUserId");

	var nextTaskValue = nextTask.getValue();

	nextUser.load(path + "/flowpage.do?method=getProcessTaskBacklogUsers&usertaskid="
					+ nextTaskValue + "&proc_def_id =" + data);
	var data1 = nextUser.getData();
	 if(data1 == null || data1 =="")
   {
	   nextUser.setValue("");
	}
   else
   {
	var data2 = data1[0].id;
    nextUser.setValue(data2);
   }

}
//运行业务表单联动查询时使用
 function onChanged() {
	var busienssKey = mini.getbyName("id");
	var businessKeyVaule = busienssKey.getValue();
	var nextTask = mini.getbyName("nextTaskId");
	var nextUser = mini.getbyName("nextUserId");

	var nextTaskValue = nextTask.getValue();

	nextUser
			.load( path + "/flowpage.do?method=getProcessTaskBacklogUsers1&usertaskid="
					+ nextTaskValue + "&businessKey=" + businessKeyVaule);
	
   var data = nextUser.getData();
   if(data == null || data =="")
   {
	   nextUser.setValue("");
	}
   else
   {
	   var data1 = data[0].id;
       nextUser.setValue(data1); 
   }

}



//标准权限方法接口定义
function SetPageDataQx(json) {
	var json = mini.decode(json);
	
	for ( var i = 0;i < json.length; i++) 
	{
		for ( var key in json[i]) 
		{

			var keys = json[i][key].toLowerCase().split(",");
			
			if (keys[1] == '1') 
			{
				mini.getbyName(keys[0]).setReadOnly(true);
				mini.getbyName(keys[0]).addCls("asLabel");
			} else if (keys[1] == '2')
			{
				$("#" + keys[0]).hide();
				$("#" + keys[0] + "_lable").hide();
			}
		}
	}
}
//关闭弹出窗口
 function CloseWindow(action) {            
          
            if (window.CloseOwnerWindow) 
            {
             return window.CloseOwnerWindow(action);
            
            }
            else
            {
             window.close(); 
            }           
        }
 //调用后台插入表sing_in 实现签收记录
function insertSing_in(data)
 {
	  $.ajax({
      url: path + "/flowpage.do?method=insertSing_in&businessKey=" + data,
      cache: false,
      success: function (text)
      {
      var o = mini.decode(text);
       }
     });    
 }


  
function comBack()
{
	var form = new mini.Form("form1");
   var form2 = new mini.Form("form2");
     var o = form.getData();
      var o2 = form2.getData();
           // grid.loading("保存中，请稍后......");
            var json={
              data:mini.encode([o]),
              itemJson: mini.encode([o2])
            };
              $.ajax({
                url: path + "/flowpage.do?method=comback",
                type: 'post',
                data: json,
                cache: false,
                success: function (text) {
                      if("1" == text)
                      {
                       alert("办理成功");
                      }
                      else
                      {
                      alert(text);
                      }
                     
                      CloseWindow("cancel"); 
               
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                     CloseWindow("cancel"); 
                }
            });
         
       }

//中止流程
function endFlow()
{
	var form = new mini.Form("form1");
    var form2 = new mini.Form("form2");
     var o = form.getData();
      var o2 = form2.getData();
           // grid.loading("保存中，请稍后......");
            var json={
              data:mini.encode([o]),
              itemJson: mini.encode([o2])
            };
              $.ajax({
                url: path + "/flowpage.do?method=endFlow",
                type: 'post',
                data: json,
                cache: false,
                success: function (text) {
                      if("1" == text)
                      {
                       alert("办理成功");
                      }
                      else
                      {
                      alert(text);
                      }
                     
                      CloseWindow("cancel"); 
               
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                     CloseWindow("cancel"); 
                }
            });
         
       }
      
//弹出办理窗口
          function openWindow(data) {
                var text = data[0];
                mini.open({
                    url: bootPATH + "../" + data[1] + "?params=" + data[2],
                    title: "业务办理", width: 900, height: 500,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { id: text};
                        iframe.contentWindow.SetData(data);
                        
                    },
                    ondestroy: function (action) {
                        grid.reload();
                        
                    }
                });
        }
       
          //弹出暂存
           function openWindow1(data,jspPath) {
                var text =  data.split("+");
                var tt = text[0] + "+" + text[1];
                mini.open({
                    url: bootPATH + ".."+jspPath+"?params=" + text[2],
                    title: "暂存业务办理", width: 900, height: 500,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { id: tt};
                        iframe.contentWindow.SetData1(data);
                        
                    },
                    ondestroy: function (action) {
                        grid.reload();
                        
                    }
                });
        }
           
           
           function openWindow4(data) {
        	  
               var text = data.split("@");
               var value = text[0];
               mini.open({
                   url: bootPATH + ".."+text[1],
                   title: "数据信息", width: 900, height: 450,
                   onload: function () {
                       var iframe = this.getIFrameEl();
                       var data1 = { id: value};
                     
                       iframe.contentWindow.SetData(data1);
                       
                   },
                   ondestroy: function (action) {
                       grid.reload();
                       
                   }
               });
       }
           
          function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record._uid;
            var businessKey = record.business_id;
            var rowIndex = e.rowIndex;

            var s =  '<a target=\'_blank\' href=\'/ywpt/showFlowAction.do?method=showFlow&id='+businessKey+'\'>查看流程图</a>'
             +
            ' &nbsp &nbsp <a class="Edit_Button" href="javascript:edit(\'' + uid + '\')">办理</a>'

                        
            return s;
        }
          
           function onActionRenderer1(e) {
            var grid = e.sender;
            var record = e.record;
            var businessKey = record.id;
            var uid = record._uid;
           
            var rowIndex = e.rowIndex;

            var s =  '<a target=\'_blank\' href=\'/ywpt/showFlowAction.do?method=showFlow&id='+businessKey+'\'>查看流程图</a>'
             +
            '&nbsp &nbsp <a class="Edit_Button" href="javascript:edit(\'' + uid + '\')">查看</a>'

                        
            return s;
        }
           
           
      function openPictureWindow(data) {
        	  
               mini.open({
                   url: bootPATH + "../"+data,
                   title: "数据信息", width: 900, height: 450,
                   onload: function () {
                       
                       
                   },
                   ondestroy: function (action) {
                       grid.reload();
                       
                   }
               });
       }
 